package com.example.springaop2.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.*;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @RequestMapping(value = "/login")
    public boolean login(HttpServletRequest request,String username, String password){
        boolean result = false;
        if(StringUtils.hasLength(username) && StringUtils.hasLength(password)){
            if(username.equals("admin") && password.equals("admin")){
                HttpSession session =  request.getSession(true);
                session.setAttribute("userinfo","userinfo");
                result = true;
            }
        }
        return result;
    }

    @RequestMapping(value = "/index2")
    public String index2(HttpServletRequest request,String username, String password){
        Object o = null;
        o.equals("a");
        return  "hello index";
    }
    @RequestMapping(value = "/index")
    public String index(HttpServletRequest request,String username, String password){
        int num = 10 / 0;
        return  "hello index";
    }
    @RequestMapping(value = "/reg")
    public int reg(){
        return 1;
    }
}
